class Volatile implements Runnable {
    //定义一个布尔类型，用修改布尔值看这一过程
    private volatile boolean b = false;

    public boolean isB() {
        return b;
    }

    public void setB(boolean b) {
        this.b = b;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(50);//模拟网络延迟
        } catch (InterruptedException e) {
        }
        //把修改b的值
        b = true;
        //输出b的值
        System.out.println("b=" + isB());
    }
}
public class Test5 {
    public static void main(String[] args) {
        Volatile v = new Volatile();
        Thread th = new Thread(v);
        th.start();
        while(true){
            //判断v是否修改成功，修改成功就输出进来啦
            if(v.isB()){
                System.out.println("进来啦");
                break;
            }
        }
    }
}